package com.alumni_circle.core.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author  龙小虬
 * @create  2020-07-04 00:19
 * @Configuration 用于定义配置类，可替换xml配置文件，被注解的类内部包含有一个或多个被@Bean注解的方法，
 *      这些方法将会被AnnotationConfigApplicationContext或AnnotationConfigWebApplicationContext类进行扫描，
 *      并用于构建bean定义，初始化Spring容器。
 * @EnableWebMvc https://www.cnblogs.com/lvbinbin2yujie/p/10624584.html
 *
 * 接口访问：http://localhost:8080/swagger-ui.html
 **/
@Configuration
@EnableSwagger2
@EnableWebMvc
//@WebAppConfiguration
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo()).select()
//                //扫描指定包中的swagger注解
//                .apis(RequestHandlerSelectors.basePackage("com.alumni_circle"))
                //扫描所有 有@Controller、@Api并被扫描类
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("ssm-security Api")
                .description("ssm-security项目后台API接口文档")
                .termsOfServiceUrl("https://www.lcsum.top/")
                .license("foolishlong666@qq.com")
                .version("1.0.0")
                .build();
    }


}
